package com.ala4.oxcafe.entity;

import com.ala4.oxcafe.core.entity.BaseEntity;
import com.ala4.oxcafe.enums.StorageTypeEnum;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;

/**
 * 系统附件存储实体
 *
 * @author PING
 * @date 2025/8/12 22:50
 */
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("attachments")
@Schema(description = "系统附件存储实体")
public class Attachment extends BaseEntity {

    @Schema(description = "附件唯一ID")
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    private Long id;

    @Schema(description = "原始文件名")
    @TableField("file_name")
    private String fileName;

    @Schema(description = "系统生成唯一标识（用于下载）")
    @TableField("file_key")
    @NotNull(message = "附件key不能为空", groups = Save.class)
    @NotEmpty(message = "附件key不能为空", groups = Save.class)
    private String fileKey;

    @Schema(description = "文件大小（字节）")
    @TableField("file_size")
    private Integer fileSize;

    @Schema(description = "文件类型（如：image/png）")
    @TableField("file_type")
    private String fileType;

    @Schema(description = "存储类型（OSS/LOCAL）")
    @TableField("storage_type")
    private StorageTypeEnum storageType;

    @Schema(description = "存储路径（相对路径）")
    @TableField("storage_path")
    private String storagePath;

    @Schema(description = "上传状态(0未知,1已上传)")
    private Integer uploadStatus = 0;

    @Schema(description = "上传者用户ID")
    @TableField("uploader_id")
    private Long uploaderId;

    @Schema(description = "上传时间")
    @TableField("upload_time")
    private LocalDateTime uploadTime;

    @Schema(description = "下载次数统计")
    @TableField("download_count")
    private Integer downloadCount;

    @Schema(description = "关联模块（如：用户头像/文章附件）")
    @TableField("related_module")
    private String relatedModule;

    @Schema(description = "关联业务ID")
    @TableField("related_id")
    private Long relatedId;

    public interface Save {
    }

}
